#include "treewidgetiterator.h"
#include <QTreeWidgetItemIterator>
#include <QScriptContext>
#include <scriptmanager.h>
#include <QTreeWidget>

QScriptValue  treeWidgetIterator(QScriptContext *context, QScriptEngine *engine)
{
    QTreeWidget* treeWidget = qobject_cast<QTreeWidget*>(context->argument(0).toQObject());
    TreeWidgetIterator* sb = new TreeWidgetIterator(treeWidget);

    return engine->newQObject(sb, QScriptEngine::ScriptOwnership);
}

TreeWidgetIterator::TreeWidgetIterator(QTreeWidget *tree) :
    QObject(0),
    m_iterator(new QTreeWidgetItemIterator(tree))
{
}

void TreeWidgetIterator::next()
{
    ++(*m_iterator);
}

void TreeWidgetIterator::previous()
{
    --(*m_iterator);
}

#include <QDebug>
QTreeWidgetItem * TreeWidgetIterator::data()
{
    //qDebug()<< *(*m_iterator);
    //QTreeWidgetItem* item = *(*m_iterator);
    //if(item!=0)
    //item->setData(0, Qt::CheckStateRole, QVariant());
    return *(*m_iterator);
}
